<template>
  <div class="rule-container">
    <div class="create-container">
      <el-button type="primary" @click="openVisible">增加停车计费规则</el-button>
      <!-- <el-button @click="exportToExcel">导出Excel</el-button> -->
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table :data="ruleList" style="width: 100%">
        <el-table-column type="index" label="序号" />
        <el-table-column label="计费规则编号" prop="ruleNumber" />
        <el-table-column label="计费规则名称" prop="ruleName" />
        <el-table-column label="免费时长(分钟)" prop="freeDuration" />
        <el-table-column label="收费上限(元)" prop="chargeCeiling" />
        <el-table-column label="计费方式">
          <template #default="scope">
            {{ formatChargeType(scope.row.chargeType ) }}
          </template>
        </el-table-column>
        <el-table-column label="计费规则" prop="ruleNameView" />
        <el-table-column label="操作" fixed="right" width="120">
          <template>
            <el-button size="mini" type="text">编辑</el-button>
            <el-button size="mini" type="text" @click="del()">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-dialog
      title="添加计费规则"
      :visible.sync="dialogVisible"
      width="35%"
      :before-close="handleClose"
    >
      <span>  计费规则编号</span>
      <el-input placeholder="请输入计费规则编号" />
      <span>  计费规则名称</span>
      <el-input placeholder="请输入计费规则名称" />
      <span>  计费方式(全天收费)</span>
      <div style="margin: 20px 10px ">
        <el-radio v-model="radio2" label="1" border size="medium">时长收费</el-radio>
        <el-radio v-model="radio2" label="2" border size="medium">按次收费</el-radio>
        <el-radio v-model="radio2" label="3" border size="medium">分段收费</el-radio>
      </div>
      <div>
        <span style="display: flex;">免费时长</span>
        <el-input-number v-model="num" controls-position="right" :min="1" :max="10" @change="handleChange" />
      </div>
      <span style="margin-left: 50px;">收费上限</span>

      <el-input v-model="input" placeholder="请输入内容" />
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="dialogVisible = false">确 定</el-button>

    </el-dialog>
  </div>
</template>

<script>
import { getRuleListAPI } from '@/api/car'

export default {
  name: 'Building',
  data() {
    return {
      radio2: '1',
      ruleList: [],
      params: {
        page: 1,
        pageSize: 10
      },
      total: 0,
      dialogVisible: false
    }
  },
  created() {
    this.getRuleList()
  },
  methods: {
    openVisible() {
      this.dialogVisible = true
    },
    formatChargeType(type) {
      const TYPEMAP = {
        'duration': '按时长收费',
        'turn': '按次收费',
        'partition': '分段收费'
      }
      return TYPEMAP[type]
    },
    // async exportToExcel() {
    //   const data = await downloadAPI()
    //   FileSaver.saveAs(data, '停车计费规则.xlsx')
    // },
    async  getRuleList() {
      const res = await getRuleListAPI()
      this.ruleList = res.data.rows
    }
  }
}
</script>

<style lang="scss" scoped>
.rule-container {
  padding: 20px;
  background-color: #fff;
}

.rules .el-form-item {
  padding:0 10px;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  padding-bottom: 20px;

  .search-label {
    width: 100px;
  }

  .search-main {
    width: 220px;
    margin-right: 10px;
  }
}
.create-container{
  margin: 10px 0px;
}
.page-container{
  padding:4px 0px;
  text-align: right;
}
.form-container{
  padding:0px 80px;
}
</style>
